// pages/menu/menu.js
Page({

  /**
   * 页面的初始数据
   */
  data: {

    isChecked:0,
    list:[
            {
              "image":"/images/大豆及制品.png",
              "name":"豆类及制品",
              color:"white"
            },
            {
              "image":"/images/调味品.png",
              "name":"调味品",
      color:"white"
            },
            {
              "image":"/images/坚果类.png",
              "name":"坚果类"
            },
            {
              "image":"/images/零食及冷饮.png",
              "name":"零食及冷饮"
            },
            {
              "image":"/images/肉类.png",
              "name":"肉蛋类"
            },
            {
              "image":"/images/奶类.png",
              "name":"奶类"
            },
            {
              "image":"/images/其他.png",
              "name":"其他"
            },
            {
              "image":"/images/蔬菜菌藻类.png",
              "name":"蔬菜菌藻类"
            },
            {
              "image":"/images/水果类.png",
              "name":"水果类"
            },
            {
              "image":"/images/饮料类.png",
              "name":"饮料类"
            },
            {
              "image":"/images/主食类.png",
              "name":"主食类"
            },
            {
              "image":"/images/油脂类.png",
              "name":"油脂类"
            }
          ]    
  },
  choose(){
    this.setData({
      isChecked:true
    })
  },
    
  handleClick(e){
    let list=this.data.list;
    this.setData({
      isChecked:this.data.isChecked+1
    })
    console.log(this.data.isChecked)
    console.log(list);
    for(var item in list){
      let index='list['+item+'].color';
      if(e.currentTarget.id==list[item].name&&this.data.isChecked<=3){
        console.log(list[item].name);
        this.setData({
          [index]:"pink"
        })
      }
      if(this.data.isChecked>3){
        wx.showToast({
          title:'最多可以选三种',
          icon:"'none",
          duration:2000
        })
      }
   
    }
  },



  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})